#line 1 "..\\..\\Driver\\Source\\rtc.c"
 








 

#line 1 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdio.h"
 
 
 





 






 







 




  
 








#line 47 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdio.h"


  



    typedef unsigned int size_t;    









 
 

 



    typedef struct __va_list __va_list;






   




 




typedef struct __fpos_t_struct {
    unsigned __int64 __pos;
    



 
    struct {
        unsigned int __state1, __state2;
    } __mbstate;
} fpos_t;
   


 


   

 

typedef struct __FILE FILE;
   






 

#line 136 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdio.h"


extern FILE __stdin, __stdout, __stderr;
extern FILE *__aeabi_stdin, *__aeabi_stdout, *__aeabi_stderr;

#line 166 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdio.h"
    

    

    





     



   


 


   


 

   



 

   


 




   


 





    


 






extern __declspec(__nothrow) int remove(const char *  ) __attribute__((__nonnull__(1)));
   





 
extern __declspec(__nothrow) int rename(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   








 
extern __declspec(__nothrow) FILE *tmpfile(void);
   




 
extern __declspec(__nothrow) char *tmpnam(char *  );
   











 

extern __declspec(__nothrow) int fclose(FILE *  ) __attribute__((__nonnull__(1)));
   







 
extern __declspec(__nothrow) int fflush(FILE *  );
   







 
extern __declspec(__nothrow) FILE *fopen(const char * __restrict  ,
                           const char * __restrict  ) __attribute__((__nonnull__(1,2)));
   








































 
extern __declspec(__nothrow) FILE *freopen(const char * __restrict  ,
                    const char * __restrict  ,
                    FILE * __restrict  ) __attribute__((__nonnull__(2,3)));
   








 
extern __declspec(__nothrow) void setbuf(FILE * __restrict  ,
                    char * __restrict  ) __attribute__((__nonnull__(1)));
   




 
extern __declspec(__nothrow) int setvbuf(FILE * __restrict  ,
                   char * __restrict  ,
                   int  , size_t  ) __attribute__((__nonnull__(1)));
   















 
#pragma __printf_args
extern __declspec(__nothrow) int fprintf(FILE * __restrict  ,
                    const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   


















 
#pragma __printf_args
extern __declspec(__nothrow) int _fprintf(FILE * __restrict  ,
                     const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   



 
#pragma __printf_args
extern __declspec(__nothrow) int printf(const char * __restrict  , ...) __attribute__((__nonnull__(1)));
   




 
#pragma __printf_args
extern __declspec(__nothrow) int _printf(const char * __restrict  , ...) __attribute__((__nonnull__(1)));
   



 
#pragma __printf_args
extern __declspec(__nothrow) int sprintf(char * __restrict  , const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   






 
#pragma __printf_args
extern __declspec(__nothrow) int _sprintf(char * __restrict  , const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   



 

#pragma __printf_args
extern __declspec(__nothrow) int __ARM_snprintf(char * __restrict  , size_t  ,
                     const char * __restrict  , ...) __attribute__((__nonnull__(3)));


#pragma __printf_args
extern __declspec(__nothrow) int snprintf(char * __restrict  , size_t  ,
                     const char * __restrict  , ...) __attribute__((__nonnull__(3)));
   















 

#pragma __printf_args
extern __declspec(__nothrow) int _snprintf(char * __restrict  , size_t  ,
                      const char * __restrict  , ...) __attribute__((__nonnull__(3)));
   



 
#pragma __scanf_args
extern __declspec(__nothrow) int fscanf(FILE * __restrict  ,
                    const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   






























 
#pragma __scanf_args
extern __declspec(__nothrow) int _fscanf(FILE * __restrict  ,
                     const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   



 
#pragma __scanf_args
extern __declspec(__nothrow) int scanf(const char * __restrict  , ...) __attribute__((__nonnull__(1)));
   






 
#pragma __scanf_args
extern __declspec(__nothrow) int _scanf(const char * __restrict  , ...) __attribute__((__nonnull__(1)));
   



 
#pragma __scanf_args
extern __declspec(__nothrow) int sscanf(const char * __restrict  ,
                    const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   








 
#pragma __scanf_args
extern __declspec(__nothrow) int _sscanf(const char * __restrict  ,
                     const char * __restrict  , ...) __attribute__((__nonnull__(1,2)));
   



 

 
extern __declspec(__nothrow) int vfscanf(FILE * __restrict  , const char * __restrict  , __va_list) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) int vscanf(const char * __restrict  , __va_list) __attribute__((__nonnull__(1)));
extern __declspec(__nothrow) int vsscanf(const char * __restrict  , const char * __restrict  , __va_list) __attribute__((__nonnull__(1,2)));

extern __declspec(__nothrow) int _vfscanf(FILE * __restrict  , const char * __restrict  , __va_list) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) int _vscanf(const char * __restrict  , __va_list) __attribute__((__nonnull__(1)));
extern __declspec(__nothrow) int _vsscanf(const char * __restrict  , const char * __restrict  , __va_list) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) int __ARM_vsscanf(const char * __restrict  , const char * __restrict  , __va_list) __attribute__((__nonnull__(1,2)));

extern __declspec(__nothrow) int vprintf(const char * __restrict  , __va_list  ) __attribute__((__nonnull__(1)));
   





 
extern __declspec(__nothrow) int _vprintf(const char * __restrict  , __va_list  ) __attribute__((__nonnull__(1)));
   



 
extern __declspec(__nothrow) int vfprintf(FILE * __restrict  ,
                    const char * __restrict  , __va_list  ) __attribute__((__nonnull__(1,2)));
   






 
extern __declspec(__nothrow) int vsprintf(char * __restrict  ,
                     const char * __restrict  , __va_list  ) __attribute__((__nonnull__(1,2)));
   






 
extern __declspec(__nothrow) int __ARM_vsnprintf(char * __restrict  , size_t  ,
                     const char * __restrict  , __va_list  ) __attribute__((__nonnull__(3)));

extern __declspec(__nothrow) int vsnprintf(char * __restrict  , size_t  ,
                     const char * __restrict  , __va_list  ) __attribute__((__nonnull__(3)));
   







 

extern __declspec(__nothrow) int _vsprintf(char * __restrict  ,
                      const char * __restrict  , __va_list  ) __attribute__((__nonnull__(1,2)));
   



 
extern __declspec(__nothrow) int _vfprintf(FILE * __restrict  ,
                     const char * __restrict  , __va_list  ) __attribute__((__nonnull__(1,2)));
   



 
extern __declspec(__nothrow) int _vsnprintf(char * __restrict  , size_t  ,
                      const char * __restrict  , __va_list  ) __attribute__((__nonnull__(3)));
   



 

#pragma __printf_args
extern __declspec(__nothrow) int asprintf(char **  , const char * __restrict  , ...) __attribute__((__nonnull__(2)));
extern __declspec(__nothrow) int vasprintf(char **  , const char * __restrict  , __va_list  ) __attribute__((__nonnull__(2)));

#pragma __printf_args
extern __declspec(__nothrow) int __ARM_asprintf(char **  , const char * __restrict  , ...) __attribute__((__nonnull__(2)));
extern __declspec(__nothrow) int __ARM_vasprintf(char **  , const char * __restrict  , __va_list  ) __attribute__((__nonnull__(2)));
   








 

extern __declspec(__nothrow) int fgetc(FILE *  ) __attribute__((__nonnull__(1)));
   







 
extern __declspec(__nothrow) char *fgets(char * __restrict  , int  ,
                    FILE * __restrict  ) __attribute__((__nonnull__(1,3)));
   










 
extern __declspec(__nothrow) int fputc(int  , FILE *  ) __attribute__((__nonnull__(2)));
   







 
extern __declspec(__nothrow) int fputs(const char * __restrict  , FILE * __restrict  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) int getc(FILE *  ) __attribute__((__nonnull__(1)));
   







 




    extern __declspec(__nothrow) int (getchar)(void);

   





 
extern __declspec(__nothrow) char *gets(char *  ) __attribute__((__nonnull__(1)));
   









 
extern __declspec(__nothrow) int putc(int  , FILE *  ) __attribute__((__nonnull__(2)));
   





 




    extern __declspec(__nothrow) int (putchar)(int  );

   



 
extern __declspec(__nothrow) int puts(const char *  ) __attribute__((__nonnull__(1)));
   





 
extern __declspec(__nothrow) int ungetc(int  , FILE *  ) __attribute__((__nonnull__(2)));
   






















 

extern __declspec(__nothrow) size_t fread(void * __restrict  ,
                    size_t  , size_t  , FILE * __restrict  ) __attribute__((__nonnull__(1,4)));
   











 

extern __declspec(__nothrow) size_t __fread_bytes_avail(void * __restrict  ,
                    size_t  , FILE * __restrict  ) __attribute__((__nonnull__(1,3)));
   











 

extern __declspec(__nothrow) size_t fwrite(const void * __restrict  ,
                    size_t  , size_t  , FILE * __restrict  ) __attribute__((__nonnull__(1,4)));
   







 

extern __declspec(__nothrow) int fgetpos(FILE * __restrict  , fpos_t * __restrict  ) __attribute__((__nonnull__(1,2)));
   








 
extern __declspec(__nothrow) int fseek(FILE *  , long int  , int  ) __attribute__((__nonnull__(1)));
   














 
extern __declspec(__nothrow) int fsetpos(FILE * __restrict  , const fpos_t * __restrict  ) __attribute__((__nonnull__(1,2)));
   










 
extern __declspec(__nothrow) long int ftell(FILE *  ) __attribute__((__nonnull__(1)));
   











 
extern __declspec(__nothrow) void rewind(FILE *  ) __attribute__((__nonnull__(1)));
   





 

extern __declspec(__nothrow) void clearerr(FILE *  ) __attribute__((__nonnull__(1)));
   




 

extern __declspec(__nothrow) int feof(FILE *  ) __attribute__((__nonnull__(1)));
   


 
extern __declspec(__nothrow) int ferror(FILE *  ) __attribute__((__nonnull__(1)));
   


 
extern __declspec(__nothrow) void perror(const char *  );
   









 

extern __declspec(__nothrow) int _fisatty(FILE *   ) __attribute__((__nonnull__(1)));
    
 

extern __declspec(__nothrow) void __use_no_semihosting_swi(void);
extern __declspec(__nothrow) void __use_no_semihosting(void);
    





 











#line 1021 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdio.h"



 

#line 13 "..\\..\\Driver\\Source\\rtc.c"
#line 1 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"
 
 
 




 
 



 






   














  


 








#line 54 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"


  



    typedef unsigned int size_t;    
#line 70 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"






    



    typedef unsigned short wchar_t;  
#line 91 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"

typedef struct div_t { int quot, rem; } div_t;
    
typedef struct ldiv_t { long int quot, rem; } ldiv_t;
    

typedef struct lldiv_t { long long quot, rem; } lldiv_t;
    


#line 112 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"
   



 

   




 
#line 131 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"
   


 
extern __declspec(__nothrow) int __aeabi_MB_CUR_MAX(void);

   




 

   




 




extern __declspec(__nothrow) double atof(const char *  ) __attribute__((__nonnull__(1)));
   



 
extern __declspec(__nothrow) int atoi(const char *  ) __attribute__((__nonnull__(1)));
   



 
extern __declspec(__nothrow) long int atol(const char *  ) __attribute__((__nonnull__(1)));
   



 

extern __declspec(__nothrow) long long atoll(const char *  ) __attribute__((__nonnull__(1)));
   



 


extern __declspec(__nothrow) double strtod(const char * __restrict  , char ** __restrict  ) __attribute__((__nonnull__(1)));
   

















 

extern __declspec(__nothrow) float strtof(const char * __restrict  , char ** __restrict  ) __attribute__((__nonnull__(1)));
extern __declspec(__nothrow) long double strtold(const char * __restrict  , char ** __restrict  ) __attribute__((__nonnull__(1)));
   

 

extern __declspec(__nothrow) long int strtol(const char * __restrict  ,
                        char ** __restrict  , int  ) __attribute__((__nonnull__(1)));
   



























 
extern __declspec(__nothrow) unsigned long int strtoul(const char * __restrict  ,
                                       char ** __restrict  , int  ) __attribute__((__nonnull__(1)));
   


























 

 
extern __declspec(__nothrow) long long strtoll(const char * __restrict  ,
                                  char ** __restrict  , int  )
                          __attribute__((__nonnull__(1)));
   




 
extern __declspec(__nothrow) unsigned long long strtoull(const char * __restrict  ,
                                            char ** __restrict  , int  )
                                   __attribute__((__nonnull__(1)));
   



 

extern __declspec(__nothrow) int rand(void);
   







 
extern __declspec(__nothrow) void srand(unsigned int  );
   






 

struct _rand_state { int __x[57]; };
extern __declspec(__nothrow) int _rand_r(struct _rand_state *);
extern __declspec(__nothrow) void _srand_r(struct _rand_state *, unsigned int);
struct _ANSI_rand_state { int __x[1]; };
extern __declspec(__nothrow) int _ANSI_rand_r(struct _ANSI_rand_state *);
extern __declspec(__nothrow) void _ANSI_srand_r(struct _ANSI_rand_state *, unsigned int);
   


 

extern __declspec(__nothrow) void *calloc(size_t  , size_t  );
   



 
extern __declspec(__nothrow) void free(void *  );
   





 
extern __declspec(__nothrow) void *malloc(size_t  );
   



 
extern __declspec(__nothrow) void *realloc(void *  , size_t  );
   













 

extern __declspec(__nothrow) int posix_memalign(void **  , size_t  , size_t  );
   









 

typedef int (*__heapprt)(void *, char const *, ...);
extern __declspec(__nothrow) void __heapstats(int (*  )(void *  ,
                                           char const *  , ...),
                        void *  ) __attribute__((__nonnull__(1)));
   










 
extern __declspec(__nothrow) int __heapvalid(int (*  )(void *  ,
                                           char const *  , ...),
                       void *  , int  ) __attribute__((__nonnull__(1)));
   














 
extern __declspec(__nothrow) __declspec(__noreturn) void abort(void);
   







 

extern __declspec(__nothrow) int atexit(void (*  )(void)) __attribute__((__nonnull__(1)));
   




 
#line 436 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"


extern __declspec(__nothrow) __declspec(__noreturn) void exit(int  );
   












 

extern __declspec(__nothrow) __declspec(__noreturn) void _Exit(int  );
   







      

extern __declspec(__nothrow) char *getenv(const char *  ) __attribute__((__nonnull__(1)));
   









 

extern __declspec(__nothrow) int  system(const char *  );
   









 

extern  void *bsearch(const void *  , const void *  ,
              size_t  , size_t  ,
              int (*  )(const void *, const void *)) __attribute__((__nonnull__(1,2,5)));
   












 
#line 524 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"


extern  void qsort(void *  , size_t  , size_t  ,
           int (*  )(const void *, const void *)) __attribute__((__nonnull__(1,4)));
   









 

#line 553 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"

extern __declspec(__nothrow) __attribute__((const)) int abs(int  );
   



 

extern __declspec(__nothrow) __attribute__((const)) div_t div(int  , int  );
   









 
extern __declspec(__nothrow) __attribute__((const)) long int labs(long int  );
   



 




extern __declspec(__nothrow) __attribute__((const)) ldiv_t ldiv(long int  , long int  );
   











 







extern __declspec(__nothrow) __attribute__((const)) long long llabs(long long  );
   



 




extern __declspec(__nothrow) __attribute__((const)) lldiv_t lldiv(long long  , long long  );
   











 
#line 634 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"




 
typedef struct __sdiv32by16 { int quot, rem; } __sdiv32by16;
typedef struct __udiv32by16 { unsigned int quot, rem; } __udiv32by16;
    
typedef struct __sdiv64by32 { int rem, quot; } __sdiv64by32;

__value_in_regs extern __declspec(__nothrow) __attribute__((const)) __sdiv32by16 __rt_sdiv32by16(
     int  ,
     short int  );
   

 
__value_in_regs extern __declspec(__nothrow) __attribute__((const)) __udiv32by16 __rt_udiv32by16(
     unsigned int  ,
     unsigned short  );
   

 
__value_in_regs extern __declspec(__nothrow) __attribute__((const)) __sdiv64by32 __rt_sdiv64by32(
     int  , unsigned int  ,
     int  );
   

 




 
extern __declspec(__nothrow) unsigned int __fp_status(unsigned int  , unsigned int  );
   







 























 
extern __declspec(__nothrow) int mblen(const char *  , size_t  );
   












 
extern __declspec(__nothrow) int mbtowc(wchar_t * __restrict  ,
                   const char * __restrict  , size_t  );
   















 
extern __declspec(__nothrow) int wctomb(char *  , wchar_t  );
   













 





 
extern __declspec(__nothrow) size_t mbstowcs(wchar_t * __restrict  ,
                      const char * __restrict  , size_t  ) __attribute__((__nonnull__(2)));
   














 
extern __declspec(__nothrow) size_t wcstombs(char * __restrict  ,
                      const wchar_t * __restrict  , size_t  ) __attribute__((__nonnull__(2)));
   














 

extern __declspec(__nothrow) void __use_realtime_heap(void);
extern __declspec(__nothrow) void __use_realtime_division(void);
extern __declspec(__nothrow) void __use_two_region_memory(void);
extern __declspec(__nothrow) void __use_no_heap(void);
extern __declspec(__nothrow) void __use_no_heap_region(void);

extern __declspec(__nothrow) char const *__C_library_version_string(void);
extern __declspec(__nothrow) int __C_library_version_number(void);











#line 892 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdlib.h"





 
#line 14 "..\\..\\Driver\\Source\\rtc.c"
#line 1 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
 
 
 
 




 








 












#line 38 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"


  



    typedef unsigned int size_t;    
#line 54 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"




extern __declspec(__nothrow) void *memcpy(void * __restrict  ,
                    const void * __restrict  , size_t  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) void *memmove(void *  ,
                    const void *  , size_t  ) __attribute__((__nonnull__(1,2)));
   







 
extern __declspec(__nothrow) char *strcpy(char * __restrict  , const char * __restrict  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) char *strncpy(char * __restrict  , const char * __restrict  , size_t  ) __attribute__((__nonnull__(1,2)));
   





 

extern __declspec(__nothrow) char *strcat(char * __restrict  , const char * __restrict  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) char *strncat(char * __restrict  , const char * __restrict  , size_t  ) __attribute__((__nonnull__(1,2)));
   






 






 

extern __declspec(__nothrow) int memcmp(const void *  , const void *  , size_t  ) __attribute__((__nonnull__(1,2)));
   





 
extern __declspec(__nothrow) int strcmp(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) int strncmp(const char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   






 
extern __declspec(__nothrow) int strcasecmp(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   





 
extern __declspec(__nothrow) int strncasecmp(const char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   






 
extern __declspec(__nothrow) int strcoll(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   







 

extern __declspec(__nothrow) size_t strxfrm(char * __restrict  , const char * __restrict  , size_t  ) __attribute__((__nonnull__(2)));
   













 


#line 193 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) void *memchr(const void *  , int  , size_t  ) __attribute__((__nonnull__(1)));

   





 

#line 209 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strchr(const char *  , int  ) __attribute__((__nonnull__(1)));

   




 

extern __declspec(__nothrow) size_t strcspn(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   




 

#line 232 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strpbrk(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));

   




 

#line 247 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strrchr(const char *  , int  ) __attribute__((__nonnull__(1)));

   





 

extern __declspec(__nothrow) size_t strspn(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   



 

#line 270 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strstr(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));

   





 

extern __declspec(__nothrow) char *strtok(char * __restrict  , const char * __restrict  ) __attribute__((__nonnull__(2)));
extern __declspec(__nothrow) char *_strtok_r(char *  , const char *  , char **  ) __attribute__((__nonnull__(2,3)));

extern __declspec(__nothrow) char *strtok_r(char *  , const char *  , char **  ) __attribute__((__nonnull__(2,3)));

   

































 

extern __declspec(__nothrow) void *memset(void *  , int  , size_t  ) __attribute__((__nonnull__(1)));
   



 
extern __declspec(__nothrow) char *strerror(int  );
   





 
extern __declspec(__nothrow) size_t strlen(const char *  ) __attribute__((__nonnull__(1)));
   



 

extern __declspec(__nothrow) size_t strlcpy(char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   
















 

extern __declspec(__nothrow) size_t strlcat(char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   






















 

extern __declspec(__nothrow) void _membitcpybl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpybb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpyhl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpyhb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpywl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpywb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovebl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovebb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovehl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovehb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovewl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovewb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
    














































 







#line 502 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"



 

#line 15 "..\\..\\Driver\\Source\\rtc.c"
#line 1 "..\\..\\Driver\\Include\\nuc970.h"
 










 






































 




#line 1 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"
 
 





 









     
#line 27 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"
     











#line 46 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"





 

     

     
typedef   signed          char int8_t;
typedef   signed short     int int16_t;
typedef   signed           int int32_t;
typedef   signed       __int64 int64_t;

     
typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;
typedef unsigned       __int64 uint64_t;

     

     
     
typedef   signed          char int_least8_t;
typedef   signed short     int int_least16_t;
typedef   signed           int int_least32_t;
typedef   signed       __int64 int_least64_t;

     
typedef unsigned          char uint_least8_t;
typedef unsigned short     int uint_least16_t;
typedef unsigned           int uint_least32_t;
typedef unsigned       __int64 uint_least64_t;

     

     
typedef   signed           int int_fast8_t;
typedef   signed           int int_fast16_t;
typedef   signed           int int_fast32_t;
typedef   signed       __int64 int_fast64_t;

     
typedef unsigned           int uint_fast8_t;
typedef unsigned           int uint_fast16_t;
typedef unsigned           int uint_fast32_t;
typedef unsigned       __int64 uint_fast64_t;

     




typedef   signed           int intptr_t;
typedef unsigned           int uintptr_t;


     
typedef   signed     long long intmax_t;
typedef unsigned     long long uintmax_t;




     

     





     





     





     

     





     





     





     

     





     





     





     

     






     






     






     

     


     


     


     

     
#line 216 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"

     



     






     
    
 



#line 241 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"

     







     










     











#line 305 "C:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"






 
#line 57 "..\\..\\Driver\\Include\\nuc970.h"




 

 
#line 82 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 120 "..\\..\\Driver\\Include\\nuc970.h"

   

 
 
 



 

 



 

#line 174 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 200 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 216 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 260 "..\\..\\Driver\\Include\\nuc970.h"

#line 295 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 329 "..\\..\\Driver\\Include\\nuc970.h"

   



 



 
#line 362 "..\\..\\Driver\\Include\\nuc970.h"

#line 373 "..\\..\\Driver\\Include\\nuc970.h"

#line 384 "..\\..\\Driver\\Include\\nuc970.h"

#line 395 "..\\..\\Driver\\Include\\nuc970.h"

#line 406 "..\\..\\Driver\\Include\\nuc970.h"

#line 417 "..\\..\\Driver\\Include\\nuc970.h"

#line 428 "..\\..\\Driver\\Include\\nuc970.h"

#line 439 "..\\..\\Driver\\Include\\nuc970.h"

#line 450 "..\\..\\Driver\\Include\\nuc970.h"

#line 461 "..\\..\\Driver\\Include\\nuc970.h"

#line 472 "..\\..\\Driver\\Include\\nuc970.h"

#line 483 "..\\..\\Driver\\Include\\nuc970.h"

#line 496 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 540 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 567 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 608 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

 
#line 624 "..\\..\\Driver\\Include\\nuc970.h"





 
#line 638 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 655 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 669 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 677 "..\\..\\Driver\\Include\\nuc970.h"

 



   


 



 

 
#line 698 "..\\..\\Driver\\Include\\nuc970.h"





 
#line 713 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

 



 
#line 738 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 746 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 812 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 862 "..\\..\\Driver\\Include\\nuc970.h"

 
#line 886 "..\\..\\Driver\\Include\\nuc970.h"

   




 



 

#line 914 "..\\..\\Driver\\Include\\nuc970.h"






 
#line 937 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 957 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 977 "..\\..\\Driver\\Include\\nuc970.h"




 
#line 998 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 1018 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 1038 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 1058 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 1078 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 1098 "..\\..\\Driver\\Include\\nuc970.h"



 
#line 1118 "..\\..\\Driver\\Include\\nuc970.h"


   


 



 























   

 



 

#line 1166 "..\\..\\Driver\\Include\\nuc970.h"

#line 1174 "..\\..\\Driver\\Include\\nuc970.h"

#line 1182 "..\\..\\Driver\\Include\\nuc970.h"

#line 1190 "..\\..\\Driver\\Include\\nuc970.h"
   

 



 




   

 



 






   

 



 

#line 1238 "..\\..\\Driver\\Include\\nuc970.h"

#line 1255 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 1301 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 1323 "..\\..\\Driver\\Include\\nuc970.h"

#line 1336 "..\\..\\Driver\\Include\\nuc970.h"

#line 1349 "..\\..\\Driver\\Include\\nuc970.h"

#line 1362 "..\\..\\Driver\\Include\\nuc970.h"

#line 1375 "..\\..\\Driver\\Include\\nuc970.h"

#line 1388 "..\\..\\Driver\\Include\\nuc970.h"

#line 1401 "..\\..\\Driver\\Include\\nuc970.h"

#line 1414 "..\\..\\Driver\\Include\\nuc970.h"

#line 1427 "..\\..\\Driver\\Include\\nuc970.h"

#line 1440 "..\\..\\Driver\\Include\\nuc970.h"




   


 



 

#line 1484 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 1499 "..\\..\\Driver\\Include\\nuc970.h"

#line 1506 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 1527 "..\\..\\Driver\\Include\\nuc970.h"

#line 1539 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 1566 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 1600 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 1636 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 1658 "..\\..\\Driver\\Include\\nuc970.h"

   

 



 

#line 1706 "..\\..\\Driver\\Include\\nuc970.h"

#line 1746 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 

#line 1771 "..\\..\\Driver\\Include\\nuc970.h"

   


 



 
#line 1823 "..\\..\\Driver\\Include\\nuc970.h"

   



   





 

typedef volatile unsigned char  vu8;        
typedef volatile unsigned short vu16;       
typedef volatile unsigned long  vu32;       





 







 







 








 







 








 







 







 






 








 







 








 







 







 






 



   

 
 
 



 
typedef void *            PVOID;    
typedef void              VOID;     
typedef char              BOOL;     
typedef char *            PBOOL;    

typedef char              INT8;     
typedef char              CHAR;     
typedef char *            PINT8;    
typedef char *            PCHAR;    
typedef unsigned char     UINT8;    
typedef unsigned char     UCHAR;    
typedef unsigned char *   PUINT8;   
typedef unsigned char *   PUCHAR;   
typedef char *            PSTR;     
typedef const char *      PCSTR;    

typedef short             SHORT;    
typedef short *           PSHORT;   
typedef unsigned short    USHORT;   
typedef unsigned short *  PUSHORT;  

typedef short             INT16;    
typedef short *           PINT16;   
typedef unsigned short    UINT16;   
typedef unsigned short *  PUINT16;  

typedef int               INT;      
typedef int *             PINT;     
typedef unsigned int      UINT;     
typedef unsigned int *    PUINT;    

typedef int               INT32;    
typedef int *             PINT32;   
typedef unsigned int      UINT32;   
typedef unsigned int *    PUINT32;  

typedef __int64           INT64;    
typedef unsigned __int64  UINT64;   

typedef float             FLOAT;    
typedef float *           PFLOAT;   

typedef double            DOUBLE;   
typedef double *          PDOUBLE;  

typedef int               SIZE_T;   

typedef unsigned char     REG8;     
typedef unsigned short    REG16;    
typedef unsigned int      REG32;    
















 
#line 2070 "..\\..\\Driver\\Include\\nuc970.h"

 













   
#line 16 "..\\..\\Driver\\Source\\rtc.c"
#line 1 "..\\..\\Driver\\Include\\sys.h"
 








 











 



 



 



 
typedef enum IRQn {

     

    WDT_IRQn                = 1,        
    WWDT_IRQn               = 2,        
    LVD_IRQn                = 3,        
    EINT0_IRQn              = 4,        
    EINT1_IRQn              = 5,        
    EINT2_IRQn              = 6,        
    EINT3_IRQn              = 7,        
    EINT4_IRQn              = 8,        
    EINT5_IRQn              = 9,        
    EINT6_IRQn              = 10,       
    EINT7_IRQn              = 11,       
    ACTL_IRQn               = 12,       
    LCD_IRQn                = 13,       
    CAP_IRQn                = 14,       
    RTC_IRQn                = 15,       
    TMR0_IRQn               = 16,       
    TMR1_IRQn               = 17,       
    ADC_IRQn                = 18,       
    EMC0_RX_IRQn            = 19,       
    EMC1_RX_IRQn            = 20,       
    EMC0_TX_IRQn            = 21,       
    EMC1_TX_IRQn            = 22,       
    EHCI_IRQn               = 23,       
    OHCI_IRQn               = 24,       
    GDMA0_IRQn              = 25,       
    GDMA1_IRQn              = 26,       
    SDH_IRQn                = 27,       
    FMI_IRQn                = 28,       
    USBD_IRQn               = 29,       
    TMR2_IRQn               = 30,       
    TMR3_IRQn               = 31,       
    TMR4_IRQn               = 32,       
    JPEG_IRQn               = 33,       
    GE2D_IRQn               = 34,       
    CRPT_IRQn               = 35,       
    UART0_IRQn              = 36,       
    UART1_IRQn              = 37,       
    UART2_IRQn              = 38,       
    UART4_IRQn              = 39,       
    UART6_IRQn              = 40,       
    UART8_IRQn              = 41,       
    UART10_IRQn             = 42,       
    UART3_IRQn              = 43,       
    UART5_IRQn              = 44,       
    UART7_IRQn              = 45,       
    UART9_IRQn              = 46,       
    ETMR0_IRQn              = 47,       
    ETMR1_IRQn              = 48,       
    ETMR2_IRQn              = 49,       
    ETMR3_IRQn              = 50,       
    SPI0_IRQn               = 51,       
    SPI1_IRQn               = 52,       
    I2C0_IRQn               = 53,       
    I2C1_IRQn               = 54,       
    SC0_IRQn                = 55,       
    SC1_IRQn                = 56,       
    GPIO_IRQn               = 57,       
    CAN0_IRQn               = 58,       
    CAN1_IRQn               = 59,       
    PWM_IRQn                = 60,       
    KPI_IRQn                = 61,       
}
IRQn_Type;

 








 
#line 121 "..\\..\\Driver\\Include\\sys.h"






 





 
#line 140 "..\\..\\Driver\\Include\\sys.h"

 





 
typedef enum CLKn {

    SYS_UPLL     = 1,    
    SYS_APLL     = 2,    
    SYS_SYSTEM   = 3,    
    SYS_HCLK1    = 4,    
    SYS_HCLK234  = 5,    
    SYS_PCLK     = 6,    
    SYS_CPU      = 7,    

}  CLK_Type;




typedef struct datetime_t {
    UINT32  year;
    UINT32  mon;
    UINT32  day;
    UINT32  hour;
    UINT32  min;
    UINT32  sec;
} DateTime_T;

 





 







 
#line 194 "..\\..\\Driver\\Include\\sys.h"

 















    




 

 
UINT32  sysGetTicks (INT32 nTimeNo);
INT32   sysResetTicks (INT32 nTimeNo);
INT32   sysUpdateTickCount(INT32 nTimeNo, UINT32 uCount);
INT32   sysSetTimerReferenceClock (INT32 nTimeNo, UINT32 uClockRate);
INT32   sysStartTimer (INT32 nTimeNo, UINT32 uTicksPerSecond, INT32 nOpMode);
INT32   sysStopTimer (INT32 nTimeNo);
void    sysClearWatchDogTimerCount (void);
void    sysClearWatchDogTimerInterruptStatus(void);
void    sysDisableWatchDogTimer (void);
void    sysDisableWatchDogTimerReset(void);
void    sysEnableWatchDogTimer (void);
void    sysEnableWatchDogTimerReset(void);
PVOID   sysInstallWatchDogTimerISR (INT32 nIntTypeLevel, PVOID pvNewISR);
INT32   sysSetWatchDogTimerInterval (INT32 nWdtInterval);
INT32   sysSetTimerEvent(INT32 nTimeNo, UINT32 uTimeTick, PVOID pvFun);
void    sysClearTimerEvent(INT32 nTimeNo, UINT32 uTimeEventNo);
void    sysSetLocalTime(DateTime_T ltime);           
void    sysGetCurrentTime(DateTime_T *curTime);      
void    sysDelay(UINT32 uTicks);

 
INT8    sysGetChar (void);
INT32   sysInitializeUART (void);
void    sysprintf (PINT8 pcStr,...);
void    sysPutChar (UINT8 ucCh);
INT     sysIsKbHit(void);

 
INT32   sysDisableInterrupt (IRQn_Type eIntNo);
INT32   sysEnableInterrupt (IRQn_Type eIntNo);
BOOL    sysGetIBitState(void);               
UINT32  sysGetInterruptEnableStatus(void);   
UINT32  sysGetInterruptEnableStatusH(void);  
PVOID   sysInstallExceptionHandler (INT32 nExceptType, PVOID pvNewHandler);
PVOID   sysInstallFiqHandler (PVOID pvNewISR);
PVOID   sysInstallIrqHandler (PVOID pvNewISR);
PVOID   sysInstallISR (INT32 nIntTypeLevel, IRQn_Type eIntNo, PVOID pvNewISR);
INT32   sysSetGlobalInterrupt (INT32 nIntState);     
INT32   sysSetInterruptPriorityLevel (IRQn_Type eIntNo, UINT32 uIntLevel);
INT32   sysSetInterruptType (IRQn_Type eIntNo, UINT32 uIntSourceType);       
INT32   sysSetLocalInterrupt (INT32 nIntState);


 
void    sysDisableCache(void);
INT32   sysEnableCache(UINT32 uCacheOpMode);
void    sysFlushCache(INT32 nCacheType);     
BOOL    sysGetCacheState(void);              
INT32   sysGetSdramSizebyMB(void);           
void    sysInvalidCache(void);               
INT32   sysSetCachePages(UINT32 addr, INT32 size, INT32 cache_mode);     

 
INT32   sysSetExternalIO(INT extNo, UINT32 extBaseAddr, UINT32 extSize, INT extBusWidth);  
INT32   sysSetExternalIOTiming1(INT extNo, INT tACC, INT tACS);  
INT32   sysSetExternalIOTiming2(INT extNo, INT tCOH, INT tCOS);  

int sysSetMMUMappingMethod(int mode);    

UINT32 sysGetClock(CLK_Type clk);

typedef void (*sys_pvFunPtr)();    
extern sys_pvFunPtr sysIrqHandlerTable[];
extern BOOL volatile _sys_bIsAICInitial;





   

   

   



 

#line 17 "..\\..\\Driver\\Source\\rtc.c"
#line 1 "..\\..\\Driver\\Include\\RTC.h"
 








 





 
 
 
#line 20 "..\\..\\Driver\\Include\\RTC.h"
#line 21 "..\\..\\Driver\\Include\\RTC.h"









 



 



 	
	
 
 
 															  
#line 52 "..\\..\\Driver\\Include\\RTC.h"







































































































































































































































































































 
typedef enum
{
	RTC_ALARM_INT   		=0x01,   
	RTC_TICK_INT     		=0x02,   
	RTC_WAKEUP_INT    	 	=0x04,   
	RTC_PSWI_INT    	 	=0x08,   
	RTC_RELATIVE_ALARM_INT  =0x10,   
	RTC_KEY_PRESS_INT       =0x20,   
	RTC_ALL_INT     		=0x3F    
}RTC_INT_SOURCE;



 
typedef enum
{
	RTC_IOC_IDENTIFY_LEAP_YEAR 		=  0,     
	RTC_IOC_SET_TICK_MODE       	=  1,     
	RTC_IOC_GET_TICK            	=  2,     
	RTC_IOC_RESTORE_TICK       		=  3,     
	RTC_IOC_ENABLE_INT         		=  4,     
	RTC_IOC_DISABLE_INT     	    =  5,     
	RTC_IOC_SET_CURRENT_TIME  		=  6,     
	RTC_IOC_SET_ALAMRM_TIME    	 	=  7,     
	RTC_IOC_SET_FREQUENCY      		=  8,	  
	RTC_IOC_SET_POWER_ON	    	=  9,     
	RTC_IOC_SET_POWER_OFF       	=  10,     
	RTC_IOC_SET_POWER_OFF_PERIOD  	=  11,     
	RTC_IOC_ENABLE_HW_POWEROFF		=  12,     
	RTC_IOC_DISABLE_HW_POWEROFF		=  13,     
	RTC_IOC_GET_POWERKEY_STATUS  	=  14,     
	RTC_IOC_SET_PSWI_CALLBACK		=  15,     
	
	
	RTC_IOC_SET_RELEATIVE_ALARM		=  18,     
	
	
	
}E_RTC_CMD;



 
typedef enum
{
 	RTC_TICK_1_SEC       =         0,       
 	RTC_TICK_1_2_SEC     =         1,       
 	RTC_TICK_1_4_SEC     =         2,       
 	RTC_TICK_1_8_SEC     =         3,       
 	RTC_TICK_1_16_SEC    =         4,       
 	RTC_TICK_1_32_SEC    =         5,        
 	RTC_TICK_1_64_SEC    =         6,       
 	RTC_TICK_1_128_SEC   =         7        
}RTC_TICK;

typedef void (PFN_RTC_CALLBACK)(void);   



 
typedef enum
{
	RTC_CURRENT_TIME    =    0,    
	RTC_ALARM_TIME      =    1     
}E_RTC_TIME_SELECT;



 
typedef enum
{
    RTC_SUNDAY         =   0,    
    RTC_MONDAY         =   1,    
    RTC_TUESDAY        =   2,    
    RTC_WEDNESDAY      =   3,    
    RTC_THURSDAY       =   4,    
    RTC_FRIDAY         =   5,    
    RTC_SATURDAY       =   6     
}E_RTC_DWR_PARAMETER;



 
typedef struct
{
    UINT8 u8cClockDisplay;             
    UINT8 u8cAmPm;                      
    UINT32 u32cSecond;                 
    UINT32 u32cMinute;                 
    UINT32 u32cHour;                   
    UINT32 u32cDayOfWeek;              
    UINT32 u32cDay;                    
    UINT32 u32cMonth;                  
    UINT32 u32Year;                    
    UINT32 u32AlarmMaskSecond;         
    UINT32 u32AlarmMaskMinute;         
    UINT32 u32AlarmMaskHour;           
    PFN_RTC_CALLBACK *pfnAlarmCallBack;     
}RTC_TIME_DATA_T;



 
typedef struct
{
    UINT8 ucMode;                            
    PFN_RTC_CALLBACK *pfnTickCallBack;       
}RTC_TICK_T;

   



 

UINT32 RTC_Init(void);   
UINT32 RTC_Open(RTC_TIME_DATA_T *sPt);
UINT32 RTC_Ioctl(INT32 i32Num, E_RTC_CMD eCmd, UINT32 u32Arg0, UINT32 u32Arg1);
UINT32 RTC_Read(E_RTC_TIME_SELECT eTime, RTC_TIME_DATA_T *sPt);
UINT32 RTC_Write(E_RTC_TIME_SELECT eTime, RTC_TIME_DATA_T *sPt);
UINT32 RTC_DoFrequencyCompensation(INT32 i32FrequencyX100);
UINT32 RTC_WriteEnable (BOOL bEnable);
UINT32 RTC_Close(void);
void RTC_EnableClock(BOOL bEnable);

   

   

   







 



#line 18 "..\\..\\Driver\\Source\\rtc.c"



 



 



 



static PFN_RTC_CALLBACK  *g_pfnRTCCallBack_Tick    = 0, *g_pfnRTCCallBack_Alarm   = 0, *g_pfnRTCCallBack_PSWI   = 0, *g_pfnRTCCallBack_Relative_Alarm =0;

static UINT32 volatile g_u32RTC_Count  = 0;
static CHAR g_chHourMode = 0;
static BOOL volatile g_bIsEnableTickInt  = (0);
static BOOL volatile g_bIsEnableAlarmInt = (0);

static UINT32 volatile g_u32Reg, g_u32Reg1,g_u32hiYear,g_u32loYear,g_u32hiMonth,g_u32loMonth,g_u32hiDay,g_u32loDay;
static UINT32 volatile g_u32hiHour,g_u32loHour,g_u32hiMin,g_u32loMin,g_u32hiSec,g_u32loSec;
UINT32 volatile i, Wait;

VOID RTC_Check(void)
{
    i =0;

    Wait = (*((volatile unsigned int *)((0xB8004000+0x2C)))) & (0x1ul << (31));

    while(Wait == (0x1ul << (31)))
    {

        Wait = (*((volatile unsigned int *)((0xB8004000+0x2C)))) & (0x1ul << (31));

        i++;

        if(i > 0xFFFFFFFF)
        {
            
            break;
        }
    }
}

static void RTC_ISR (void)
{
    UINT32 volatile u32RegINTSTS;

    u32RegINTSTS = (*((volatile unsigned int *)((0xB8004000+0x2C))));

    if (u32RegINTSTS & RTC_TICK_INT)                                      
    {
        RTC_WriteEnable(1);
        *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_TICK_INT;
        RTC_Check();

        g_u32RTC_Count++;                                               

        if (g_pfnRTCCallBack_Tick != 0)                              
        {
            g_pfnRTCCallBack_Tick();
        }

    }
    if (u32RegINTSTS & RTC_ALARM_INT)                                     
    {
        RTC_WriteEnable(1);
        *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_ALARM_INT;
        RTC_Check();

        if (g_pfnRTCCallBack_Alarm != 0)                              
        {
            g_pfnRTCCallBack_Alarm();
        }
    }
    if (u32RegINTSTS & RTC_RELATIVE_ALARM_INT)                             
    {
        RTC_WriteEnable(1);
        *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_RELATIVE_ALARM_INT;
        RTC_Check();

        RTC_Ioctl(0,RTC_IOC_DISABLE_INT,RTC_RELATIVE_ALARM_INT,0);

        if (g_pfnRTCCallBack_Relative_Alarm != 0)                     
        {
            g_pfnRTCCallBack_Relative_Alarm();
            g_pfnRTCCallBack_Relative_Alarm = 0;
        }

    }
    if (u32RegINTSTS & RTC_PSWI_INT)                                         
    {
        RTC_WriteEnable(1);
        *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_PSWI_INT;
        RTC_Check();

        

        if (g_pfnRTCCallBack_PSWI != 0)                               
        {
            g_pfnRTCCallBack_PSWI();
        }
    }

}











 
UINT32 RTC_DoFrequencyCompensation(INT32 i32FrequencyX100)
{
    INT32 i32RegInt, i32RegFra;
    UINT32 u32Reg;

     
    i32RegInt = (i32FrequencyX100 / 100) - 32761;
    i32RegFra = (((i32FrequencyX100 % 100)) * 60) / 100;

     
    if((i32RegInt < 0) | (i32RegInt > 15))
    {
        return 5;
    }

    u32Reg = (uint32_t)((i32RegInt << 8) | i32RegFra);

    RTC_WriteEnable(1);
    *((volatile unsigned int *)((0xB8004000+0x08))) = u32Reg;
    RTC_Check();

    return 0;
}










 
UINT32 RTC_WriteEnable (BOOL bEnable)
{
    INT32 volatile i32i;

    RTC_Check();

    if(bEnable)
    {
        *((volatile unsigned int *)((0xB8004000+0x04))) = 0xa965;
        RTC_Check();

        for (i32i = 0 ; i32i < 0xFFFFFFFF ; i32i++)
        {
             
             
             
            if ( (*((volatile unsigned int *)((0xB8004000+0x04)))) & 0x10000)
            {
                break;
            }
        }

        if (i32i == 0xFFFFFFFF)
        {
            

            return 6;
        }
    }
    else
    {
        for (i32i = 0 ; i32i < 0xFFFFFFFF ; i32i++)
        {
            if ( (*((volatile unsigned int *)((0xB8004000+0x04)))) == 0)
            {
                break;
            }
        }
    }

    return 0;
}









 
UINT32 RTC_Init (void)
{
    INT32 i32i;

     
     
     
    g_pfnRTCCallBack_Alarm = 0;
    g_pfnRTCCallBack_Tick = 0;
    g_pfnRTCCallBack_PSWI = 0;
    g_pfnRTCCallBack_Relative_Alarm = 0;
    g_u32RTC_Count = 0;
     
     
     

    *((volatile unsigned int *)((0xB8004000+0x00))) = 0xa5eb1357;
    RTC_Check();

    for (i32i = 0 ; i32i < 0xFFFFFFFF ; i32i++)
    {
        if ( (*((volatile unsigned int *)((0xB8004000+0x00)))) & 0x01 )
        {
             
            break;
        }
    }

    if (i32i == 0xFFFFFFFF)
    {
        return 6;
    }

     
     
     

    *((volatile unsigned int *)((0xB8004000+0x04))) = 0xa965;
    RTC_Check();

    for (i32i = 0 ; i32i < 0xFFFFFFFF ; i32i++)
    {
         
         
         
        if ( (*((volatile unsigned int *)((0xB8004000+0x04)))) & 0x10000)
        {
            break;
        }
    }

    if (i32i == 0xFFFFFFFF)
    {
        return 6;
    }

    sysInstallISR(1, RTC_IRQn, (PVOID)RTC_ISR);
    sysSetLocalInterrupt(0x7F);
    sysEnableInterrupt(RTC_IRQn);

    return 0;
}























 
UINT32 RTC_Open (RTC_TIME_DATA_T *sPt)
{
    UINT32 volatile u32Reg;

     
     
     
    if ( ((sPt->u32Year - 2000) > 99)|
            ((sPt->u32cMonth == 0) || (sPt->u32cMonth > 12))|
            ((sPt->u32cDay   == 0) || (sPt->u32cDay   > 31)))
    {
        return 1;
    }

    if (sPt->u8cClockDisplay == 0)
    {
        if ( (sPt->u32cHour == 0) || (sPt->u32cHour > 12) )
        {
            return 2 ;
        }
    }
    else if (sPt->u8cClockDisplay == 1)
    {
        if (sPt->u32cHour > 23)
        {
            return 2 ;
        }
    }
    else
    {
        return 2 ;
    }

    if ((sPt->u32cMinute > 59) |
            (sPt->u32cSecond > 59) |
            (sPt->u32cSecond > 59))
    {
        return 3 ;
    }
    if (sPt->u32cDayOfWeek > 6)
    {
        return 4 ;
    }

     
     
     
    if (sPt->u8cClockDisplay == 0)
    {
        g_chHourMode = 0;

        RTC_WriteEnable(1);
        *((volatile unsigned int *)((0xB8004000+0x14))) = 0;
        RTC_Check();

         
         
         
        if (sPt->u8cAmPm == 2)
            sPt->u32cHour += 20;
    }
    else                                                                                
    {
        g_chHourMode = 1;

        RTC_WriteEnable(1);
        *((volatile unsigned int *)((0xB8004000+0x14))) = 1;
        RTC_Check();
    }


    g_u32hiHour  = sPt->u32cHour / 10;
    g_u32loHour  = sPt->u32cHour % 10;
    g_u32hiMin   = sPt->u32cMinute / 10;
    g_u32loMin   = sPt->u32cMinute % 10;
    g_u32hiSec   = sPt->u32cSecond / 10;
    g_u32loSec   = sPt->u32cSecond % 10;
    u32Reg     = (g_u32hiHour << 20);
    u32Reg    |= (g_u32loHour << 16);
    u32Reg    |= (g_u32hiMin << 12);
    u32Reg    |= (g_u32loMin << 8);
    u32Reg    |= (g_u32hiSec << 4);
    u32Reg    |= g_u32loSec;
    g_u32Reg = u32Reg;

    RTC_WriteEnable(1);
    *((volatile unsigned int *)((0xB8004000+0x0C))) = (UINT32)g_u32Reg;
    RTC_Check();

    if (sPt->u8cClockDisplay == 0)
    {
        if (sPt->u8cAmPm == 2)
            sPt->u32cHour -= 20;
    }

    g_u32hiYear  = (sPt->u32Year - 2000) / 10;
    g_u32loYear  = (sPt->u32Year - 2000) % 10;
    g_u32hiMonth =  sPt->u32cMonth              / 10;
    g_u32loMonth =  sPt->u32cMonth              % 10;
    g_u32hiDay   =  sPt->u32cDay                / 10;
    g_u32loDay   =  sPt->u32cDay                % 10;
    u32Reg    = (g_u32hiYear << 20);
    u32Reg    |= (g_u32loYear << 16);
    u32Reg    |= (g_u32hiMonth << 12);
    u32Reg    |= (g_u32loMonth << 8);
    u32Reg    |= (g_u32hiDay << 4);
    u32Reg    |= g_u32loDay;
    g_u32Reg = u32Reg;

    RTC_WriteEnable(1);
    *((volatile unsigned int *)((0xB8004000+0x10))) = (UINT32)g_u32Reg;
    RTC_Check();

    RTC_WriteEnable(1);
    *((volatile unsigned int *)((0xB8004000+0x18))) = (UINT32)sPt->u32cDayOfWeek;
    RTC_Check();

    return 0;
}
























 
UINT32 RTC_Read (E_RTC_TIME_SELECT eTime, RTC_TIME_DATA_T *sPt)
{
    UINT32 u32Tmp;

    sPt->u8cClockDisplay = (*((volatile unsigned int *)((0xB8004000+0x14))));                                
    sPt->u32cDayOfWeek = (*((volatile unsigned int *)((0xB8004000+0x18))));                                   

    switch (eTime)
    {
        case RTC_CURRENT_TIME:
        {
            g_u32Reg   = (*((volatile unsigned int *)((0xB8004000+0x10))));
            g_u32Reg1  = (*((volatile unsigned int *)((0xB8004000+0x0C))));
            break;
        }
        case RTC_ALARM_TIME:
        {
            g_u32Reg   = (*((volatile unsigned int *)((0xB8004000+0x20))));
            g_u32Reg1  = (*((volatile unsigned int *)((0xB8004000+0x1C))));
            break;
        }
        default:
        {
            return 7;
        }
    }

    g_u32hiYear  = (g_u32Reg & 0xF00000) >> 20;
    g_u32loYear  = (g_u32Reg & 0xF0000) >> 16;
    g_u32hiMonth = (g_u32Reg & 0x1000) >> 12;
    g_u32loMonth = (g_u32Reg & 0xF00) >> 8;
    g_u32hiDay   = (g_u32Reg & 0x30) >> 4;
    g_u32loDay   =  g_u32Reg & 0xF;

    u32Tmp = (g_u32hiYear * 10);
    u32Tmp+= g_u32loYear;
    sPt->u32Year   =   u32Tmp  + 2000;

    u32Tmp = (g_u32hiMonth * 10);
    sPt->u32cMonth = u32Tmp + g_u32loMonth;

    u32Tmp = (g_u32hiDay * 10);
    sPt->u32cDay   =  u32Tmp  + g_u32loDay;

    g_u32hiHour = (g_u32Reg1 & 0x300000) >> 20;
    g_u32loHour = (g_u32Reg1 & 0xF0000) >> 16;
    g_u32hiMin  = (g_u32Reg1 & 0x7000) >> 12;
    g_u32loMin  = (g_u32Reg1 & 0xF00) >> 8;
    g_u32hiSec  = (g_u32Reg1 & 0x70) >> 4;
    g_u32loSec  =  g_u32Reg1 & 0xF;

    if (sPt->u8cClockDisplay == 0)
    {
        u32Tmp = (g_u32hiHour * 10);
        u32Tmp+= g_u32loHour;
        sPt->u32cHour = u32Tmp;                                 

        if(eTime ==RTC_CURRENT_TIME)
        {
            if (sPt->u32cHour >= 21)
            {
                sPt->u8cAmPm = 2;
                sPt->u32cHour -= 20;
            }
            else
            {
                sPt->u8cAmPm = 1;
            }
        }
        else
        {
            if (sPt->u32cHour < 12)
            {
                if(sPt->u32cHour == 0)
                    sPt->u32cHour = 12;
                sPt->u8cAmPm = 1;
            }
            else
            {
                sPt->u32cHour -= 12;
                sPt->u8cAmPm = 2;
            }
        }

        u32Tmp = (g_u32hiMin  * 10);
        u32Tmp+= g_u32loMin;
        sPt->u32cMinute = u32Tmp;

        u32Tmp = (g_u32hiSec  * 10);
        u32Tmp+= g_u32loSec;
        sPt->u32cSecond = u32Tmp;

    }
    else
    {
         
        u32Tmp = (g_u32hiHour * 10);
        u32Tmp+= g_u32loHour;
        sPt->u32cHour   = u32Tmp;

        u32Tmp = (g_u32hiMin  * 10);
        u32Tmp+= g_u32loMin;
        sPt->u32cMinute = u32Tmp;

        u32Tmp = (g_u32hiSec  * 10);
        u32Tmp+= g_u32loSec;
        sPt->u32cSecond = u32Tmp;
    }

    return 0;

}



























 
UINT32 RTC_Write(E_RTC_TIME_SELECT eTime, RTC_TIME_DATA_T *sPt)
{
    UINT32 u32Reg;

     
     
     
    if ( ((sPt->u32Year - 2000) > 99)|
            ((sPt->u32cMonth == 0) || (sPt->u32cMonth > 12))|
            ((sPt->u32cDay   == 0) || (sPt->u32cDay   > 31)))
    {
        return 1;
    }

    if ( (sPt->u32Year - 2000) > 99 )
    {
        return 1;
    }

    if ( (sPt->u32cMonth == 0) || (sPt->u32cMonth > 12) )
    {
        return 1;
    }

    if ( (sPt->u32cDay == 0) || (sPt->u32cDay > 31) )
    {
        return 1;
    }

    if (sPt->u8cClockDisplay == 0)
    {
        if ( (sPt->u32cHour == 0) || (sPt->u32cHour > 12) )
        {
            return 3;
        }
    }
    else if (sPt->u8cClockDisplay == 1)
    {
        if (sPt->u32cHour > 23)
        {
            return 3;
        }
    }
    else
    {
        return 3;
    }

    if (sPt->u32cMinute > 59)
    {
        return 3;
    }

    if (sPt->u32cSecond > 59)
    {
        return 3;
    }

    if (sPt->u32cDayOfWeek > 6)
    {
        return 4;
    }

    switch (eTime)
    {

        case RTC_CURRENT_TIME:
        {
             
             
             

            if (sPt->u8cClockDisplay == 0)
            {
                g_chHourMode = 0;

                RTC_WriteEnable(1);
                *((volatile unsigned int *)((0xB8004000+0x14))) = 0;
                RTC_Check();

                 
                 
                 
                if (sPt->u8cAmPm == 2)
                {
                    sPt->u32cHour += 20;
                }
            }
            else                                                                   
            {
                g_chHourMode = 1;

                RTC_WriteEnable(1);
                *((volatile unsigned int *)((0xB8004000+0x14))) = 1;
                RTC_Check();

            }

            g_u32hiHour  = sPt->u32cHour / 10;
            g_u32loHour  = sPt->u32cHour % 10;
            g_u32hiMin   = sPt->u32cMinute / 10;
            g_u32loMin   = sPt->u32cMinute % 10;
            g_u32hiSec   = sPt->u32cSecond / 10;
            g_u32loSec   = sPt->u32cSecond % 10;

            u32Reg = (g_u32hiHour << 20);
            u32Reg|= (g_u32loHour << 16);
            u32Reg|= (g_u32hiMin << 12);
            u32Reg|= (g_u32loMin << 8);
            u32Reg|= (g_u32hiSec << 4);
            u32Reg|= g_u32loSec;
            g_u32Reg = u32Reg;

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x0C))) = (UINT32)g_u32Reg;
            RTC_Check();

            g_u32hiYear  = (sPt->u32Year - 2000) / 10;
            g_u32loYear  = (sPt->u32Year - 2000) % 10;
            g_u32hiMonth = sPt->u32cMonth / 10;
            g_u32loMonth = sPt->u32cMonth % 10;
            g_u32hiDay   = sPt->u32cDay / 10;
            g_u32loDay   = sPt->u32cDay % 10;

            u32Reg = (g_u32hiYear << 20);
            u32Reg|= (g_u32loYear << 16);
            u32Reg|= (g_u32hiMonth << 12);
            u32Reg|= (g_u32loMonth << 8);
            u32Reg|= (g_u32hiDay << 4);
            u32Reg|= g_u32loDay;
            g_u32Reg = u32Reg;

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x10))) = (UINT32)g_u32Reg;
            RTC_Check();

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x18))) = (UINT32) sPt->u32cDayOfWeek;
            RTC_Check();

            if (sPt->u8cClockDisplay == 0)
            {
                if (sPt->u8cAmPm == 2)
                {
                    sPt->u32cHour -= 20;
                }
            }

            return 0;

        }
        case RTC_ALARM_TIME:
        {
            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = (*((volatile unsigned int *)((0xB8004000+0x34)))) & ~(0x1ul << (3));
            RTC_Check();

            g_pfnRTCCallBack_Alarm = 0;                                          
             
             
             
            g_u32hiYear = (sPt->u32Year - 2000) / 10;
            g_u32loYear = (sPt->u32Year - 2000) % 10;
            g_u32hiMonth = sPt->u32cMonth / 10;
            g_u32loMonth = sPt->u32cMonth % 10;
            g_u32hiDay = sPt->u32cDay / 10;
            g_u32loDay = sPt->u32cDay % 10;

            
            u32Reg = ((sPt->u32cDayOfWeek & 0x7) << 24);
            
            u32Reg|= (g_u32hiYear << 20);
            u32Reg|= (g_u32loYear << 16);
            
            u32Reg|= (g_u32hiMonth << 12);
            u32Reg|= (g_u32loMonth << 8);
            
            u32Reg|= (g_u32hiDay << 4);
            u32Reg|= g_u32loDay;

            g_u32Reg = u32Reg;

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x20))) = (UINT32)g_u32Reg;
            RTC_Check();


            if (g_chHourMode == 0)
            {
                if (sPt->u8cAmPm == 2)        
                {
                    sPt->u32cHour += 20;
                }
            }
            g_u32hiHour   = sPt->u32cHour / 10;
            g_u32loHour   = sPt->u32cHour % 10;
            g_u32hiMin  = sPt->u32cMinute / 10;
            g_u32loMin  = sPt->u32cMinute % 10;
            g_u32hiSec  = sPt->u32cSecond / 10;
            g_u32loSec  = sPt->u32cSecond % 10;

            u32Reg = ((sPt->u32AlarmMaskHour & 0x1) << 30);
            u32Reg|= (g_u32hiHour << 20);
            u32Reg|= (g_u32loHour << 16);
            u32Reg|= ((sPt->u32AlarmMaskMinute & 0x1) << 29);
            u32Reg|= (g_u32hiMin << 12);
            u32Reg|= (g_u32loMin << 8);
            u32Reg|= ((sPt->u32AlarmMaskSecond & 0x1) << 28);
            u32Reg|= (g_u32hiSec << 4);
            u32Reg|= g_u32loSec;

            g_u32Reg = u32Reg;

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x1C))) = (UINT32)g_u32Reg;
            RTC_Check();

            if (sPt->u8cClockDisplay == 0)
            {
                if (sPt->u8cAmPm == 2)
                {
                    sPt->u32cHour -= 20;
                }
            }
             
             
             
            if (sPt->pfnAlarmCallBack != 0)
            {
                g_pfnRTCCallBack_Alarm = sPt->pfnAlarmCallBack;
            }
             
             
             

            RTC_Ioctl(0,RTC_IOC_ENABLE_INT,RTC_ALARM_INT,0);

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = (*((volatile unsigned int *)((0xB8004000+0x34)))) | (0x1ul << (3));
            RTC_Check();

            return 0;
        }
        default:
        {
            return 7;
        }
    }

}














 
UINT32 RTC_Ioctl (INT32 i32Num, E_RTC_CMD eCmd, UINT32 u32Arg0, UINT32 u32Arg1)
{
    INT32 i32Ret;
    UINT32 u32Reg;
    RTC_TICK_T *ptick;
    UINT32 u32Tmp;

    if (i32Num != 0)
        return 8;

    switch (eCmd)
    {

        case RTC_IOC_IDENTIFY_LEAP_YEAR:
        {
            u32Reg = (*((volatile unsigned int *)((0xB8004000+0x24))));
            if (u32Reg & 0x01)
            {
                *(PUINT32)u32Arg0 = 1;
            }
            else
            {
                *(PUINT32)u32Arg0 = 0;
            }
            break;
        }
        case RTC_IOC_SET_TICK_MODE:
        {
            ptick = (RTC_TICK_T *) u32Arg0;

            if (g_bIsEnableTickInt== (1))
            {
                RTC_Ioctl(0,RTC_IOC_DISABLE_INT,RTC_TICK_INT,0);
                g_bIsEnableTickInt = (1);
            }
            g_u32RTC_Count = 0;

            if (ptick->ucMode > RTC_TICK_1_128_SEC)                             
            {
                return 7 ;
            }

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x30))) = ptick->ucMode;
            RTC_Check();

            if (ptick->pfnTickCallBack != 0)
            {
                g_pfnRTCCallBack_Tick = ptick->pfnTickCallBack;
            }
            else
            {
                g_pfnRTCCallBack_Tick = 0;
            }
             
             
             
            if (g_bIsEnableTickInt== (1))
            {

                RTC_Ioctl(0,RTC_IOC_ENABLE_INT,RTC_TICK_INT,0);

                return 0;
            }
            break;
        }

        case RTC_IOC_GET_TICK:
        {
            (*(PUINT32)u32Arg0) = g_u32RTC_Count;
            break;
        }

        case RTC_IOC_RESTORE_TICK:
        {
            g_u32RTC_Count = 0;
            break;
        }

        case RTC_IOC_ENABLE_INT:
        {

            switch ((RTC_INT_SOURCE)u32Arg0)
            {

                case RTC_TICK_INT:
                {
                    g_bIsEnableTickInt   = (1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) | RTC_TICK_INT;
                    break;
                }
                case RTC_ALARM_INT:
                {
                    g_bIsEnableAlarmInt  = (1);

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x34)))) | (0x1ul << (3));

                    *((volatile unsigned int *)((0xB8004000+0x34))) = u32Tmp;
                    *((volatile unsigned int *)((0xB8004000+0x28))) = (*((volatile unsigned int *)((0xB8004000+0x28)))) | (0x1ul << (0));

                    RTC_Check();

                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) | RTC_ALARM_INT;

                    break;
                }
                case RTC_RELATIVE_ALARM_INT:
                {
                    g_bIsEnableAlarmInt  = (1);

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x34)))) | (0x1ul << (4));

                    *((volatile unsigned int *)((0xB8004000+0x34))) = u32Tmp;
                    RTC_Check();

                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) | RTC_RELATIVE_ALARM_INT;
                    break;
                }
                case RTC_PSWI_INT:
                {
                    g_bIsEnableAlarmInt  = (1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) | RTC_PSWI_INT;
                    break;
                }
                default:
                {
                    return 7;

                }
            }

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x28))) = u32Tmp;
            RTC_Check();

            break;
        }
        case RTC_IOC_DISABLE_INT:
        {

            switch ((RTC_INT_SOURCE)u32Arg0)
            {
                case RTC_TICK_INT:
                {
                    g_bIsEnableTickInt   = (0);

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) & (~RTC_TICK_INT);

                    *((volatile unsigned int *)((0xB8004000+0x28))) = u32Tmp;

                    *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_TICK_INT;
                    RTC_Check();

                    break;
                }
                case RTC_ALARM_INT:
                {
                    g_bIsEnableAlarmInt  = (0);

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) & (~RTC_ALARM_INT);

                    *((volatile unsigned int *)((0xB8004000+0x28))) = u32Tmp;
                    RTC_Check();

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x34)))) & ~(0x1ul << (3));

                    *((volatile unsigned int *)((0xB8004000+0x34))) = u32Tmp;
                    RTC_Check();

                    *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_ALARM_INT;

                    break;
                }
                case RTC_RELATIVE_ALARM_INT:
                {
                    g_bIsEnableAlarmInt  = (0);

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) & (~RTC_RELATIVE_ALARM_INT);

                    *((volatile unsigned int *)((0xB8004000+0x28))) = u32Tmp;
                    RTC_Check();

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x34)))) & ~(0x1ul << (4));

                    *((volatile unsigned int *)((0xB8004000+0x34))) = u32Tmp;
                    RTC_Check();

                    *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_RELATIVE_ALARM_INT;

                    break;
                }
                case RTC_PSWI_INT:
                {
                    g_bIsEnableAlarmInt  = (0);

                    RTC_WriteEnable(1);
                    u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) & (~RTC_PSWI_INT);

                    *((volatile unsigned int *)((0xB8004000+0x28))) = u32Tmp;
                    RTC_Check();

                    *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_PSWI_INT;

                    break;
                }

                case RTC_ALL_INT:
                {
                    g_bIsEnableTickInt   = (0);
                    g_bIsEnableAlarmInt  = (0);

                    RTC_WriteEnable(1);
                    *((volatile unsigned int *)((0xB8004000+0x28))) = 0;
                    *((volatile unsigned int *)((0xB8004000+0x2C))) = RTC_ALL_INT;
                    RTC_Check();

                    break;
                }
                default:
                {
                    return 7;
                }
            }


            break;
        }

        case RTC_IOC_SET_FREQUENCY:
        {
            i32Ret= RTC_DoFrequencyCompensation(u32Arg0) ;
            if (i32Ret != 0)
            {
                return 7;
            }
            break;
        }
        case RTC_IOC_SET_POWER_ON:
        {
            RTC_WriteEnable(1);
            u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x34)))) | 0x01;

            *((volatile unsigned int *)((0xB8004000+0x34))) = u32Tmp;
            RTC_Check();

            while(((*((volatile unsigned int *)((0xB8004000+0x34)))) & 0x01) != 0x1);

            break;
        }
        case RTC_IOC_SET_POWER_OFF:
        {
            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = ((*((volatile unsigned int *)((0xB8004000+0x34)))) & ~0x01) | 2;
            RTC_Check();

            while(1);

            
        }
        case RTC_IOC_SET_POWER_OFF_PERIOD:
        {
            if(u32Arg0 < 4) u32Arg0 = 4;

            u32Arg0 = u32Arg0 - 4;

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = ((*((volatile unsigned int *)((0xB8004000+0x34)))) & ~0xF000) | ((u32Arg0 & 0xF) << 12);
            RTC_Check();

            break;
        }
        case RTC_IOC_ENABLE_HW_POWEROFF:
        {
            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = ((*((volatile unsigned int *)((0xB8004000+0x34)))) | 0x04);
            RTC_Check();

            break;
        }
        case RTC_IOC_DISABLE_HW_POWEROFF:
        {
            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = ((*((volatile unsigned int *)((0xB8004000+0x34)))) & ~0x04);
            RTC_Check();

            break;
        }
        case RTC_IOC_SET_PSWI_CALLBACK:
        {

            RTC_Ioctl(0, RTC_IOC_ENABLE_INT, RTC_PSWI_INT, 0);

            if (((PFN_RTC_CALLBACK  *) u32Arg0) != 0)
            {
                g_pfnRTCCallBack_PSWI = (PFN_RTC_CALLBACK  *) u32Arg0;
            }
            else
            {
                g_pfnRTCCallBack_PSWI = 0;
            }
            break;
        }
        case RTC_IOC_GET_POWERKEY_STATUS:
        {
            RTC_WriteEnable(1);
            if((*((volatile unsigned int *)((0xB8004000+0x34)))) & 0x80)
                *(PUINT32)u32Arg0 = 1;
            else
                *(PUINT32)u32Arg0 = 0;

            break;
        }
        case RTC_IOC_SET_RELEATIVE_ALARM:
        {
            g_bIsEnableAlarmInt  = (1);

            RTC_WriteEnable(1);
            *((volatile unsigned int *)((0xB8004000+0x34))) = ((*((volatile unsigned int *)((0xB8004000+0x34)))) & ~0xFFF0010);
            RTC_Check();

            RTC_WriteEnable(1);
            u32Tmp = ((*((volatile unsigned int *)((0xB8004000+0x34)))) & ~0xFFF0000)| ((u32Arg0 & 0xFFF) <<16) | (0x1ul << (4));

            *((volatile unsigned int *)((0xB8004000+0x34))) = u32Tmp;
            RTC_Check();

            g_bIsEnableAlarmInt  = (1);

            RTC_WriteEnable(1);
            u32Tmp = (*((volatile unsigned int *)((0xB8004000+0x28)))) | RTC_RELATIVE_ALARM_INT;

            *((volatile unsigned int *)((0xB8004000+0x28))) = u32Tmp;
            RTC_Check();

            if(u32Arg1 != 0)
                g_pfnRTCCallBack_Relative_Alarm =   (PFN_RTC_CALLBACK  *)u32Arg1;

            break;

        }

        default:
        {
            return 7;
        }
    }

    return 0;
}








 
UINT32 RTC_Close (void)
{

    g_bIsEnableTickInt = (0);

    sysDisableInterrupt(RTC_IRQn);


    RTC_Ioctl(0,RTC_IOC_DISABLE_INT,RTC_ALL_INT,0);


    return 0;
}









 
void RTC_EnableClock(BOOL bEnable)
{
    if(bEnable)
        *((volatile unsigned int *)((0xB0000200+0x18))) = (*((volatile unsigned int *)((0xB0000200+0x18)))) | (1 << 2);
    else
        *((volatile unsigned int *)((0xB0000200+0x18))) = (*((volatile unsigned int *)((0xB0000200+0x18)))) & ~(1 << 2);

}



   

   

   


 

